package com.hst.capacity.facade.rest;

import com.hst.capacity.application.biz.AccessControlBiz;
import com.hst.capacity.domain.model.request.SignInParam;
import com.hst.capacity.domain.model.response.DefaultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

import static com.hst.capacity.domain.model.response.DefaultVO.success;

/**
 * 访问控制Controller，包括身份验证和授权等行为
 */
@RequestMapping("/auth")
@RestController
public class AccessController {

    @Autowired
    private AccessControlBiz accessControlBiz;

    /**
     * 用户登录验证。登录成功，返回Token
     */
    @PostMapping("/sign-in")
    private DefaultVO signIn(@RequestBody @Valid SignInParam signInParam) {
        return success(accessControlBiz.signIn(signInParam));
    }

    /**
     * 用户登出。
     *
     * @return
     */
    @GetMapping("/logout/{userId}")
    public DefaultVO logout(@PathVariable String userId) {
        return success(accessControlBiz.logout(userId));
    }

    /**
     * 验证码
     */
    public void kaptcha() {

    }

    /**
     * 获取用户的绑定信息
     */
    @GetMapping("/user-binding-info/{userId}")
    private DefaultVO getUserBindingInfo(@PathVariable String userId) {
        return success(accessControlBiz.getUserBindingInfo(userId));
    }

}
